var h = $(window).height();
var allHeight = 0,
    flag =true,
    order = '',
    sendid= '',
    sessionid = '',
    imgNum = $('#allImg img').length,
    imgW = $('.infoR').width(),
    list = [],
    listName = [],
    sendMsg = [],
    comid = '';
$(document).ready(function() {
    $('.row-hoof').css('height', h);
    $('.newStyle').css({height: h - 20 + 'px'});
    $('.oD').css('min-height',Math.floor((h - 500) / 5) + 'px');
    for(var i = 0; i < 5; i++){
        allHeight += $('.order:eq(' + i + ')').outerHeight();
    }
    getHeight();
    $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
    btnClick();
    $(window).resize(function(){
        h =  $(window).height();
        $('.row-hoof').css('height', h);
        $('.newStyle').css({height: h - 20 + 'px'});
        allHeight = 0;
        $('.oD').css('min-height',Math.floor((h - 500) / 5) + 'px');
        for(var i = 0; i < 5; i++){
            allHeight += $('.order:eq(' + i + ')').outerHeight();
        }
        getHeight();
        $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
        if($('.order-hoof').css('display') == 'none'){
            $('.people').css('max-height',h - 110 + 'px');
            $('.message').css('max-height',h - 110 + 'px');
            $('.commit').css('max-height',h - 144 + 'px');
            $('.people').css('height',h  - 110 + 'px');
            $('.message').css('height',h - 110 + 'px');
            $('.commit').css('height',h - 144 + 'px');
        } else{
            getHeight();
            $('.people').css('height','auto');
            $('.message').css('height','auto');
            $('.commit').css('height','auto');
        }


    })
})
function btnClick(item){
    clearMsg();
    var num = Math.floor($('.case-content').height() / 40);
    $("#mation").ajaxSubmit({
        type: 'get',
        url: baseUrls + 'command/list',
        data: {
            userid: $('#userId').val()
            ,pageIndex: 1,
            pageSize: num
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response) {
            closeLoading();
            $('.ul-content').html('');
            if (response.responseCode == '1000') {
                if (response.content.list.length > 0) {
                    var status = 'null';
                    for(var i = 0; i < response.content.list.length; i++){
                        if(response.content.list[i].unreply == '0'){
                            status = '未反馈'
                        }else{
                            status = '已反馈'
                        }
                        if(response.content.list[i].unread == '0'){
                            $('.ul-content').append('<li onclick="getMsg(this)"><span class="left span"><span>' + nulls(response.content.list[i].sendorgname) + '&nbsp&nbsp('+ nulls(response.content.list[i].sendname) +')</span><em class="highLight"></em></span><span class="center span">' + response.content.list[i].comname + '</span><span class="right span">' + response.content.list[i].sendtime + '</span><span class="orderStatus span">' + status + '</span><input type="hidden" class="comid" value="' + response.content.list[i].comid + '"><input type="hidden" class="sendid" value="' + response.content.list[i].sendid + '"></li>');
                        } else {
                            $('.ul-content').append('<li onclick="getMsg(this)"><span class="left span"><span>' + nulls(response.content.list[i].sendorgname) + '&nbsp&nbsp('+ nulls(response.content.list[i].sendname) +')</span></span><span class="center span">' + response.content.list[i].comname + '</span><span class="right span">' + response.content.list[i].sendtime + '</span><span class="orderStatus span">' + status + '</span><input type="hidden" class="comid" value="' + response.content.list[i].comid + '"><input type="hidden" class="sendid" value="' + response.content.list[i].sendid + '"></li>');
                        }
                    }
                    getMsg($('.ul-content li').eq(0));
                    $('#demo_pag1').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 6,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $("#mation").ajaxSubmit({
                                type: 'get',
                                url: baseUrls + 'command/list',
                                data: {userid: $('#userId').val(),pageIndex: data.currentPage, pageSize: num},
                                beforeSend: function(){
                                    Loading();
                                },
                                success: function(response) {
                                    closeLoading();
                                    $('.ul-content').html('');
                                    if (response.responseCode == '1000') {
                                        if (response.content.list.length > 0) {
                                            var status = 'null';
                                            for(var i = 0; i < response.content.list.length; i++){
                                                if(response.content.list[i].unreply == '0'){
                                                    status = '未反馈'
                                                }else{
                                                    status = '已反馈'
                                                }
                                                if(response.content.list[i].unread == '0'){
                                                    $('.ul-content').append('<li onclick="getMsg(this)"><span class="left span"><span>' + nulls(response.content.list[i].sendorgname) + '&nbsp&nbsp('+ nulls(response.content.list[i].sendname) +')</span><em class="highLight"></em></span><span class="center span">' + response.content.list[i].comname + '</span><span class="right span">' + response.content.list[i].sendtime + '</span><span class="orderStatus span">' + status + '</span><input type="hidden" class="comid" value="' + response.content.list[i].comid + '"><input type="hidden" class="sendid" value="' + response.content.list[i].sendid + '"></li>');
                                                } else {
                                                    $('.ul-content').append('<li onclick="getMsg(this)"><span class="left span"><span>' + nulls(response.content.list[i].sendorgname) + '&nbsp&nbsp('+ nulls(response.content.list[i].sendname) +')</span></span><span class="center span">' + response.content.list[i].comname + '</span><span class="right span">' + response.content.list[i].sendtime + '</span><span class="orderStatus span">' + status + '</span><input type="hidden" class="comid" value="' + response.content.list[i].comid + '"><input type="hidden" class="sendid" value="' + response.content.list[i].sendid + '"></li>');
                                                }
                                            }
                                            getMsg($('.ul-content li').eq(0));
                                        }else{
                                            $('#demo_pag1').html('');
                                            $('.ul-content').html('');
                                            Msg('未查到数据');
                                        }
                                    }else{
                                        $('#demo_pag1').html('');
                                        $('.ul-content').html('');
                                        Msg('未查到数据');
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    $('.ul-content').html('');
                                    $('#demo_pag1').html('');
                                    Msg('未查到数据');
                                }
                            })
                        }
                    })
                }else{
                    $('#demo_pag1').html('');
                    $('.ul-content').html('');
                    Msg('未查到数据');
                }
            }else{
                $('#demo_pag1').html('');
                $('.ul-content').html('');
                Msg('未查到数据');
            }
        },
        error: function(){
            closeLoading();
            $('.ul-content').html('');
            $('#demo_pag1').html('');
            Msg('未查到数据');
        }
    })
}
function nofind(item){
    item.src = 'common/img/nothing.png';
    item.onerror = null;
}
function changeState(item){
    if($(item).val() == 2){
        $('#status').html('<option value="0">请选择</option></option><option value="1">已读</option><option value="2">未读</option>');
    }else {
        $('#status').html('');
    }
}
function getMsg(item){
    $(item).addClass('active').siblings().removeClass('active');
    clearMsg();
    order = $(item).children('.comid').val();
    sendid = $(item).children('.sendid').val();
    $.ajax({
        type: 'get',
        url: baseUrls + 'command/detail',
        data: {comid: order,userid: $('#userId').val(),sendid: sendid},
        beforeSend: function(){
            Loading();
        },
        success: function(response) {
            closeLoading();
            if (response.responseCode == '1000') {
                comid = response.content.command.comid;
                $('.h-hoof').html('指令名称：' + $(item).children('.center').html());
                if(response.content.command.caseList.length > 0){
                    for(var i = 0; i < response.content.command.caseList.length; i++){
                        $('.list-hoof').append('<ul class=""><li><span class="left">案件名称：</span><span class="right" onclick="showDetail(\''+ response.content.command.caseList[i].eventid +'\')">' + nulls(response.content.command.caseList[i].eventname) + '</span><span class="left">案件编号：</span><span class="right" onclick="showDetail(\''+ response.content.command.caseList[i].eventid +'\')">' + nulls(response.content.command.caseList[i].eventid) + '</span><input type="hidden" class="eventId" value="' + response.content.command.caseList[i].eventname + '"></li></ul>');
                    }
                }
                if(response.content.command.clueList.length > 0){
                    for(var i = 0; i < response.content.command.clueList.length; i++){
                        $('.list-hoof').append('<ul class=""><li><span class="left">线索名称：</span><span class="right"  onclick="showDetail(\''+ response.content.command.clueList[i].eventid +'\')">' + nulls(response.content.command.clueList[i].eventname) + '</span><span class="left">线索编号：</span><span class="right" onclick="showDetail(\''+ response.content.command.clueList[i].eventid +'\')">' + nulls(response.content.command.clueList[i].eventid) + '</span><input type="hidden" class="eventId" value="' + response.content.command.clueList[i].eventname + '"></li></ul>');
                    }
                }
                $('.sendCompany-hoof').append('<p class="ps"><span class="left">' + nulls(response.content.command.sendname) + '</span><span class="center sendCenter">' + nulls(response.content.command.sendorgname) + '</span><span class="right">' + nulls(response.content.command.sendtime) + '</span></p>');
                $('.sendContent-hoof').append('<p class="ps">' + nulls(response.content.command.comcontent) + '</p>');
                if(response.content.command.fileList.length > 0){
                         for(var i =0; i < response.content.command.fileList.length; i++){
                             $('.sendContent-hoof').append('<p class="p"><a href="' + baseUrls + 'download?url=' + response.content.command.fileList[i].wllj + '" class="downloadA">' + nulls(response.content.command.fileList[i].originalname) + '</a></p>');
                         }
                     }
                if(response.content.command.userList.length > 0){
                    for(var i = 0; i < response.content.command.userList.length; i++){
                        if(response.content.command.userList[i].unread == '0'){
                            $('.people-hoof').append('<li onclick="getInfo(this)"><span class="name">' + nulls(response.content.command.userList[i].username) + '<em class="highLight"></em></span><input type="hidden" class="userId" value="' + response.content.command.userList[i].userid + '"></li>');
                        } else{
                            $('.people-hoof').append('<li onclick="getInfo(this)"><span class="name">' + nulls(response.content.command.userList[i].username) + '</span><input type="hidden" class="userId" value="' + response.content.command.userList[i].userid + '"></li>');
                        }
                    }
                    for(var i = 0; i < response.content.command.receiveUsers.length; i++){
                        $('.getCompany-hoof').append('<p class="p"><span class="left">' + nulls(response.content.command.receiveUsers[i].orgname) + '</span><span class="center">' + nulls(response.content.command.receiveUsers[i].username) + '</span><span class="right">' + nulls(response.content.command.sendtime) + '</span></p>');
                    }
                    //对话框显示默认发送内容
                    // if(response.content.command.sendid == $('#userId').val()){
                    //     $('.commit-hoof').append('<p class="self"><span class="top">' + response.content.command.sendname + '：</span><br><span class="bottom">' + response.content.command.comcontent + '<span class="arrow"></span></span><span class="time">' + response.content.command.sendtime + '</span> </p>');
                    // }else{
                    //     $('.commit-hoof').append('<p class="other"><span class="top">' + response.content.command.sendname + '：</span><br><span class="bottom">' + response.content.command.comcontent + '<span class="arrow"></span></span><span class="time">' + response.content.command.sendtime + '</span></p>');
                    // }
                    // if(response.content.command.fileList.length > 0){
                    //     for(var i =0; i < response.content.command.fileList.length; i++){
                    //         if(response.content.command.sendid == $('#userId').val()){
                    //             $('.commit-hoof').append('<p class="self"><span class="top">' + response.content.command.sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content.command.fileList[i].wllj + '" class="downloadA">' + response.content.command.fileList[i].originalname + '</a><span class="arrow"></span></span><span class="time">' + response.content.command.sendtime + '</span> </p>');
                    //         }else{
                    //             $('.commit-hoof').append('<p class="other"><span class="top">' + response.content.command.sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content.command.fileList[i].wllj + '" class="downloadA">' + response.content.command.fileList[i].originalname + '</a><span class="arrow"></span></span><span class="time">' + response.content.command.sendtime + '</span></p>');
                    //         }
                    //     }
                    // }
                    for(var i = 0; i < response.content.command.replyList.length; i++){
                        if(response.content.command.replyList[i].sendid == $('#userId').val()){
                            if(response.content.command.replyList[i].wllj == null){
                                $('.commit-hoof').append('<p class="self"><span class="top">' + nulls(response.content.command.replyList[i].sendname) + '：</span><br><span class="bottom">' + nulls(response.content.command.replyList[i].content) + '<span class="arrow"></span></span><span class="time">' + nulls(response.content.command.replyList[i].time) + '</span> </p>');
                            }else{
                                $('.commit-hoof').append('<p class="self"><span class="top">' + nulls(response.content.command.replyList[i].sendname) + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content.command.replyList[i].wllj + '" class="downloadA">' + nulls(response.content.command.replyList[i].content) + '</a><span class="arrow"></span></span><span class="time">' + nulls(response.content.command.replyList[i].time) + '</span> </p>');
                            }
                        }else{
                            if(response.content.command.replyList[i].wllj == null){
                                $('.commit-hoof').append('<p class="other"><span class="top">' + nulls(response.content.command.replyList[i].sendname) + '：</span><br><span class="bottom">' + nulls(response.content.command.replyList[i].content) + '<span class="arrow"></span></span><span class="time">' + nulls(response.content.command.replyList[i].time) + '</span></p>');
                            }else{
                                $('.commit-hoof').append('<p class="other"><span class="top">' + nulls(response.content.command.replyList[i].sendname) + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content.command.replyList[i].wllj + '" class="downloadA">' + nulls(response.content.command.replyList[i].content) + '</a><span class="arrow"></span></span><span class="time">' + nulls(response.content.command.replyList[i].time) + '</span></p>');
                            }
                        }
                    }
                    if(response.content.command.replyList.length > 0){
                        sessionid = response.content.command.replyList[0].sessionid;
                    }
                    $('.commit').scrollTop($('.commit')[0].scrollHeight);
                    $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
                    $('.people-hoof li:eq(0)').addClass('active');
                }
                if(response.content.command.comlevel == '1'){
                    $('.status-hoof').append('<p class="ps">高</p>');
                } else if(response.content.command.comlevel == '2'){
                    $('.status-hoof').append('<p class="ps">中</p>');
                } else if(response.content.command.comlevel == '3'){
                    $('.status-hoof').append('<p class="ps">低</p>');
                }
                $('.status-hoof').append('<p class="ps termP">回复期限：'+ nulls(response.content.command.deadline) +'</p>');
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
function getInfo(item){
    $(item).addClass('active').siblings().removeClass('active');
    $.ajax({
        type: 'get',
        url: baseUrls + 'commandReply/detail',
        data: {cid: order, receiveid: $('#userId').val(), sendid: $(item).children('.userId').val(),userid: $('#userId').val()},
        beforeSend: function(){
            Loading();
        },
        success: function(response) {
            closeLoading();
            $('.commit-hoof').html('');
            if (response.responseCode == '1000') {
                $('.commit-hoof').html('');
                for(var i = 0; i < response.content.length; i++){
                    if(response.content[i].sendid == $('#userId').val()){
                        $('.commit-hoof').append('<p class="self"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span> </p>');
                    }else{
                        $('.commit-hoof').append('<p class="other"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span></p>');
                    }
                }
                if(response.content.length > 0){
                    sessionid =  response.content[0].sessionid;
                }
                $('.commit').scrollTop($('.commit')[0].scrollHeight);
                $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
function returnMsg(){
    var receiveid = $('.people .active').children('.userId').val(),
        receivename = $('.people .active').children('.name').html();
    if(comid.length > 0){
        if($.trim($("#inputMessage").val()).length > 0 || sendMsg.length > 0){
            if($.trim($("#inputMessage").val()).length > 0 && sendMsg.length <= 0){
                var fileObj = [];
                fileObj.push({
                    cid: order,
                    content: $.trim($("#inputMessage").val()),
                    sendid: $("#userId").val(),
                    sendname: $('#userName').val(),
                    receiveid: receiveid,
                    receivename: receivename,
                    sessionid: sessionid,
                    userid: $('#userId').val()
                });
                $.ajax({
                    type: 'post',
                    url: baseUrls + 'commandReply/add',
                    data: {replies: JSON.stringify(fileObj)},
                    beforeSend: function(){
                        Loading();
                    },
                    success: function(response) {
                        closeLoading();
                        if (response.responseCode == '1000') {
                            $('.fileBox').html('<a href="#" class="fileA"><input type="file" name="files" class="fileInput" onchange="getFile(this)"><span>附件上传</span><i class="fa fa-trash-o" aria-hidden="true" onclick="fileDelete(this)"></i></a>');
                            $('.commit-hoof').html('');
                            for(var i = 0; i < response.content.length; i++){
                                if(response.content[i].sendid == $('#userId').val()){
                                    if(response.content[i].wllj == null){
                                        $('.commit-hoof').append('<p class="self"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span> </p>');
                                    }else{
                                        $('.commit-hoof').append('<p class="self"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content[i].wllj + '" class="downloadA">' + response.content[i].content + '</a><span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span> </p>');
                                    }
                                }else{
                                    if(response.content[i].wllj == null){
                                        $('.commit-hoof').append('<p class="other"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span></p>');
                                    }else{
                                        $('.commit-hoof').append('<p class="other"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content[i].wllj + '" class="downloadA">' + response.content[i].content + '</a><span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span></p>');
                                    }
                                }
                            }
                            $('#inputMessage').val('');
                            sessionid = response.content[0].sessionid;
                            $('.commit').scrollTop($('.commit')[0].scrollHeight);
                            $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
                        }else{
                            Msg('回复失败');
                        }
                    },
                    error: function(){
                        closeLoading();
                        Msg('回复失败');
                    }
                })
            }else{
                var formData = new FormData();
                for(var i = 0; i < sendMsg.length; i++){
                    formData.append('files', sendMsg[i]);
                }
                for(var i = 0; i < listName.length; i++){
                    formData.append('fileNames', listName[i]);
                }
                $.ajax({
                    type: 'post',
                    url: uploadUrl + 'upload',
                    contentType: false,
                    processData: false,
                    data: formData,
                    beforeSend: function(){
                        Loading();
                    },
                    success: function(response) {
                        closeLoading();
                        if(response.responseCode == '1000'){
                            var fileObj = [];
                            if(response.content.files.length > 0){
                                var  type = '0';
                                for(var i = 0; i < response.content.files.length; i++){
                                    if(response.content.files[i].wllj.indexOf('mp3') > -1 || response.content.files[i].wllj.indexOf('wma') > -1 || response.content.files[i].wllj.indexOf('wav') > -1 ){
                                        type = '0';
                                    }else if(response.content.files[i].wllj.indexOf('mp4') > -1 || response.content.files[i].wllj.indexOf('rmvb') > -1 || response.content.files[i].wllj.indexOf('avi') > -1){
                                        type = '1';
                                    }else{
                                        type = '2';
                                    }
                                    if($.trim($("#inputMessage").val()).length > 0){
                                        fileObj.push({
                                            filetype: type,
                                            filename: response.content.files[i].fileName,
                                            wllj: response.content.files[i].wllj,
                                            gxlj: response.content.files[i].gxlj,
                                            userid: $('#userId').val(),
                                            username: $('#userName').val(),
                                            orgid: $('#orgId').val(),
                                            orgname: $('#orgName').val(),
                                            comid: comid,
                                            originalname: $.trim($("#inputMessage").val()),
                                            cid: order,
                                            content: list[i],
                                            sendid: $("#userId").val(),
                                            sendname: $('#userName').val(),
                                            receiveid: receiveid,
                                            receivename: receivename,
                                            sessionid: sessionid,
                                            userid: $('#userId').val()
                                        });
                                        fileObj.push({
                                            cid: order,
                                            content: $.trim($("#inputMessage").val()),
                                            sendid: $("#userId").val(),
                                            sendname: $('#userName').val(),
                                            receiveid: receiveid,
                                            receivename: receivename,
                                            sessionid: sessionid,
                                            userid: $('#userId').val()
                                        });
                                    }else{
                                        fileObj.push({
                                            filetype: type,
                                            filename: response.content.files[i].fileName,
                                            wllj: response.content.files[i].wllj,
                                            gxlj: response.content.files[i].gxlj,
                                            userid: $('#userId').val(),
                                            username: $('#userName').val(),
                                            orgid: $('#orgId').val(),
                                            orgname: $('#orgName').val(),
                                            comid: comid,
                                            originalname: list[i],
                                            cid: order,
                                            content: list[i],
                                            sendid: $("#userId").val(),
                                            sendname: $('#userName').val(),
                                            receiveid: receiveid,
                                            receivename: receivename,
                                            sessionid: sessionid,
                                            userid: $('#userId').val(),
                                        });
                                    }
                                }
                            }
                            $.ajax({
                                type: 'post',
                                url: baseUrls + 'commandReply/add',
                                data: {replies: JSON.stringify(fileObj)},
                                beforeSend: function(){
                                    Loading();
                                },
                                success: function(response) {
                                    closeLoading();
                                    if (response.responseCode == '1000') {
                                        list = [];
                                        listName = [];
                                        sendMsg = [];
                                        $('#inputMessage').val('');
                                        $('.fileBox').html('<a href="#" class="fileA"><input type="file" name="files" class="fileInput" onchange="getFile(this)"><span>附件上传</span><i class="fa fa-trash-o" aria-hidden="true" onclick="fileDelete(this)"></i></a>');
                                        $('.commit-hoof').html('');
                                        for(var i = 0; i < response.content.length; i++){
                                            if(response.content[i].sendid == $('#userId').val()){
                                                if(response.content[i].wllj == null){
                                                    $('.commit-hoof').append('<p class="self"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span> </p>');
                                                }else{
                                                    $('.commit-hoof').append('<p class="self"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content[i].wllj + '" class="downloadA">' + response.content[i].content + '</a><span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span> </p>');
                                                }
                                            }else{
                                                if(response.content[i].wllj == null){
                                                    $('.commit-hoof').append('<p class="other"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom">' + response.content[i].content + '<span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span></p>');
                                                }else{
                                                    $('.commit-hoof').append('<p class="other"><span class="top">' + response.content[i].sendname + '：</span><br><span class="bottom"><a href="' + baseUrls + 'download?url=' + response.content[i].wllj + '" class="downloadA">' + response.content[i].content + '</a><span class="arrow"></span></span><span class="time">' + response.content[i].time + '</span></p>');
                                                }
                                            }
                                        }
                                        sessionid = response.content[0].sessionid;
                                        $('.commit').scrollTop($('.commit')[0].scrollHeight);
                                        $('.bottom').css({maxWidth: $('.message').width() - 160 + 'px', display: 'inline-block'});
                                    }else{
                                        Msg('回复失败');
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg('回复失败');
                                }
                            })
                        }else{
                            Msg('回复失败');
                        }
                    },
                    error: function(){
                        closeLoading();
                        Msg('回复失败');
                    }
                });
            }
        }else{
            Msg('回复信息不能为空');
        }
    }else{
        Msg('请选择指令');
    }
}
function toggles(){
    if(flag){
        $('.order-hoof').slideUp();
        $('.people').css('max-height',h - 110 + 'px');
        $('.message').css('max-height',h - 110 + 'px');
        $('.commit').css('max-height',h - 144 + 'px');
        $('.people').css('height',h  - 110 + 'px');
        $('.message').css('height',h - 110 + 'px');
        $('.commit').css('height',h - 144 + 'px');
        flag = false;
    }else{
        $('.order-hoof').slideDown();
        $('.people').css('max-height',h - allHeight - 110 + 'px');
        $('.message').css('max-height',h - allHeight - 110 + 'px');
        $('.commit').css('max-height',h - allHeight - 144 + 'px');
        $('.people').css('height','auto');
        $('.message').css('height','auto');
        $('.commit').css('height','auto');
        flag = true;
    }
}
function getHeight(){
    if( h - allHeight - 110 > 0){
        $('.people').css('max-height',h - allHeight - 110 + 'px');
        $('.message').css('max-height',h - allHeight - 110 + 'px');
    } else{
        $('.people').css('max-height', '0px');
        $('.message').css('max-height', '0px');
    }
    if( h - allHeight - 144 > 0){
        $('.commit').css('max-height', h - allHeight - 144 + 'px');
    } else{
        $('.commit').css('max-height', '0px');
    }
}
function inputSubmit(event){
    event = event ? event: window.event;
    if(event.keyCode == '13'){
        returnMsg();
    }
}
function clearMsg(){
    order = '';
    $('.h-hoof').html('指令名称：');
    $('.common-hoof').html('');

}
function showDetail(uniq){
    layer.open({
        type: 2,
        area: ['90%', h * 0.9 + 'px'],
        fixed: false, //不固定
        maxmin: false,
        content: 'layer/layer.html?' + uniq + '&' + $('#userId').val()
    });
}
function getFile(node){
    if (node.value) {
        if (node.files && node.files[0]) {
            file = node.files[0];
        } else if (node.files && node.files.item(0)) {
            file = node.files.item(0);
        }
        if(file.size < fileSizes){
            if(list.indexOf(file.name) < 0){
                var newData = new Date();
                list.push(file.name);
                sendMsg.push(file);
                listName.push(addresses + newData.getFullYear() + '/' + (newData.getMonth() + 1) + '/' + newData.getDate() + '/' + comid + '_' + $('#userCode').val() + '_' + newData.getHours() + newData.getMinutes() + newData.getSeconds() + newData.getMilliseconds() + file.name.substr(file.name.lastIndexOf('.')));
                $(node).parent().find('span').html(file.name);
                $(node).attr('disabled','disabled');
                $(node).parent().find('i').css('display','block');
                $('.fileBox').append('<a href="#" class="fileA"><input type="file" name="files" class="fileInput" onchange="getFile(this)"><span>附件上传</span><i class="fa fa-trash-o" aria-hidden="true" onclick="fileDelete(this)"></i></a>');
            }else{
                $(node).val('');
                Msg('您已选择，如需重复选择请修改名称。');
            }
        }else{
            $(node).val('');
            Msg('您上传的文件超过' + Math.floor((fileSizes / 1024 / 1024)) + 'M。');
        }
    }
}
function fileDelete(item){
    var index = $(item).parents('a').index();
    $(item).parents('a').remove();
    list.splice(index,1);
    listName.splice(index,1);
    sendMsg.splice(index,1);
}
function fileBoxShow(){
    if(comid.length > 0){
        preventDe();
        $('.fileBox').toggleClass('fileBoxShow');
    }else{
        Msg('请选择指令');
    }
}
function hideFileBox(){
    $('.fileBox').removeClass('fileBoxShow');
}
function preventDe(event){
    var e = arguments.callee.caller.arguments[0]||event;
    if (e && e.stopPropagation) {
        e.stopPropagation();
    } else if (window.event) {
        window.event.cancelBubble = true;
    }
}